home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4264 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: hubcap.clemson.edu!hubcap!mjs
  2. From: mjs@hubcap.clemson.edu (M. J. Saltzman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: division problem
  5. Date: 2 Feb 96 21:05:00 GMT
  6. Organization: Clemson University
  7. Message-ID: <mjs.823295100@hubcap>
  8. References: <31097D77.11AA@rain.org> <26JAN199622082450@erich.triumf.ca> <4eh246$u6h@airdmhor.gen.nz> <4ej4ha$66@fountain.mindlink.net> <DLzvGG.2rn@uns.bris.ac.uk>  <Pine.SOL.3.90.960130150923.21923F-100000@flute> <4etjdj$fil@airdmhor.gen.nz>
  9. NNTP-Posting-Host: hubcap.clemson.edu
  10.  
  11. gumboot@airdmhor.gen.nz (Simon Hosie) writes:
  12.  
  13. >  Hello?  Can anybody hear me?  Ok, let's try again...
  14.  
  15. >#if -3 / 2 == -2
  16. >    celcius = ((fahrenheit - 32) * 10 + 9) / 18;
  17. >#else
  18. >    celcius = ((fahrenheit - 32) * 10 + ((fahrenheit - 32 >= 0) ? 9 : -9)) 
  19. >            / 18;
  20. >#endif
  21.  
  22. >  There.. complete, portable, accurate rounding.
  23.  
  24. I'm not so sure.  Is there a guarantee that the division as done in
  25. the compiler's preprocessing phase will give the same result as the
  26. division done at run time?  Language lawyers?
  27.  
  28. If not, then you need to do the test at run time or use div() to get 
  29. perfectly portable results.
  30. -- 
  31.         Matthew Saltzman
  32.         Clemson University Math Sciences
  33.         mjs@clemson.edu
  34.